<%@ include file="/Pages/Jsp/Common/header.jsp"%>
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic"%>
<%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles"%>
<%@page import="com.capgemini.fs.presentation.role.web.form.MaintainRoleForm"%>
<script>
$(document).ready(function(){ 
	//$("#NoticeField").fadeOut(3000);
	$("select[name='select']").attr("selectedIndex",0);
    if($(".requiredNotice").html()== ""){
        $(".requiredNotice").hide(); 
     }
});
</script>
<div style="width:960px;margin-left:auto;margin-right:auto;">
<div class="span-22 append-10 last">
      <form name="frmMaintainRole" action="<%=request.getContextPath()%>/roleMgt/maintainRole.do?action=update" method="post">
        <div class="requiredNotice error">
        </div>
        <div id="NoticeField" class="span-10 last append-14">	
		<logic:present name="Success">
			<div class="notice">
				<b>${Success}</b>
			</div>
		</logic:present>
		<logic:present name="Failed">
			<div class="error">
				<b>${Failed}</b>
			</div>
		</logic:present>
		</div>	
      	<div>
      	  <h3>Maintain Role</h3>
      	  <hr/>
        </div>
    	<hr class="space prepend">
          <p>
            <label class="span-3 append-1 align-left "><span class="errtxt">*</span> Role Name:</label>
			<html:select name="maintainRoleForm" property="select" styleClass="span-4" onchange="changeRole(this);">
				<html:option value="-- Please select --"></html:option>
				<html:optionsCollection name="maintainRoleForm" property="beanCollection"/>
			</html:select>
			<SPAN id="roleSelectError" style="display: none" class="errorText">Please select one role!</SPAN>
          </p>
          <p>
            <label class="span-3 append-1 align-left "><span class="errtxt">*</span> Role Name<br/>(After Change):</label>
            <input id="Role" name="role_name" class="span-4 redlight" type="text" onBlur="checkRoleNameMaintainRole();">
            <SPAN id="role_nameError" style="display: none" class="errorText">Please fill in the mandatory field "Role Name"!</SPAN>
            <SPAN id="role_nameExistError" style="display: none" class="errorText">The "Role Name" already exist, please fill in again!</SPAN>
          </p>
          <br/>
          <p>
            <label class="span-3 append-1 align-left "><span class="errtxt">*</span> Active:</label>
            <select id="RoleActive" name="roleActive" class="span-4">
            	<option selected="selected">Yes</option>
            	<option>No</option>
            </select>
            <SPAN id="adminError" style="display: none" class="errorText">The role "Admin" can not be inactivated by any user!</SPAN>
            <SPAN id="currentRoleError" style="display: none" class="errorText">The user current role can not be inactivated by user!</SPAN>
          </p>
          <p>
            <label class="span-4 align-left "><span class="errtxt">*</span> Permissions:</label>
          </p>
<br></br>
<table id="Permission" class="blueTable span-22">
          	<tr>
          	<th width="20%">Category</th>
          	<th width="80%">Functionalities</th>
          	</tr>
			<logic:iterate id="FunctionalityList_Cat" name="maintainRoleForm" property="categoryList"
				type="String">
          	<tr>
          		<td><bean:write name="FunctionalityList_Cat" /></td>
          		<td>
          			<logic:iterate id="FunctionalityList_Fun" name="maintainRoleForm" property="functionalityList"
						type="com.capgemini.fs.app.ekms.model.Functionality">
						<logic:equal   name= "FunctionalityList_Fun"   property= "category"   value= "${FunctionalityList_Cat}">
							<span>
							<input name="functionCheckBox" type="checkbox" value="${FunctionalityList_Fun.functionalityCode}">
          					<bean:write name="FunctionalityList_Fun" property="functionalityName" />
          					</span>
          				</logic:equal> 
          			</logic:iterate>
          		</td>
          	</tr>
          	</logic:iterate>
          	</table>
			<SPAN id="permissionError" style="display: none" class="errorText">Please assign at least one permission to a role.</SPAN>
          <div id="button">
            <input value="Save" type="button" onClick="alertRoleConfirm('maintain')">&nbsp;
            <input value="Reset" type="button" onClick="resetForm()">&nbsp;
            <input value="Back" type="button" onClick="window.location.href='<%=request.getContextPath()%>/login.do'">
          <hr class="space"/>
          </div>
          <input style="display: none" id="hiddenRoleID" name="roleId">
			<div id="popDiv" class="rolePopupDiv span-18 noDisplay" >
				<div class="popTitle span-16">Maintain Role Confirmation</div> 
				<div class="handLink span-1 closeX last" onClick="resetRoleDialog()">X</div>
				<hr></hr>
			    <div id="roleConfirm">
			    "<span id="hiddenRoleName"></span>"&nbsp;will be modified with following permissions.
			    <br>
			    <span>Active: </span><span id="hiddenActive"></span>
			    <br>
			    <span>Permissions: </span>
			    <table id="hiddenPermission" class="noDisplay"></table>
			    <div id="button">
			    <input type="Submit" onClick="" title="Submit" name="Submit" value="Save"></input>
			    <input type="Button" onClick="resetRoleDialog()" value="Back"></input>
			    </div>
			    </div>
			</div>
			<div id="loadingbg" class="bg noDisplay">
			</div>
      </form>
    </div>
  </div>
